<?php declare(strict_types=1);

namespace App\Services\PengYiPeng;


class AliAppOauthService
{


//    const Notify = "https://test-pay.zgjindoufu.com/api/v2/Notify/AliyunNotify/notify";

    const NotifyApi = "/api/v2/Redirect/Aliyun/sourceCode";

    //获取  $sysParams["app_auth_token"] = $appInfoAuthtoken;
    public function getOauthUrl(int $provider_id, string $type = "MOBILE"): string
    {

        $agentOpParam = [
            "redirectUri" => env("API_DOMAIN") . self::NotifyApi,
            "appTypes" => ["TINYAPP", "WEBAPP", "PUBLICAPP", "MOBILEAPP"],
            "isvAppId" => config("lite.threePartyApplication.appId"),
            "state" => base64_encode("provider_id:" . $provider_id)
        ];

        $bitData = [
            "platformCode" => "O",
            "taskType" => "INTERFACE_AUTH",
            "agentOpParam" => $agentOpParam
        ];

        $bitData = urlencode(json_encode($bitData));

        switch ($type) {
            case "WEB":
                $url = "https://b.alipay.com/page/message/tasksDetail?bizData=" . $bitData;
                break;
            case "MOBILE":
                //appId  三方应用的appid
                $url = "alipays://platformapi/startapp?appId=2021003130652097&page=pages%2Fauthorize%2Findex%3FbizData%3D" . $bitData;
                break;
            default:
                throw new \Exception("参数异常");
        }
//        $url = "https://openauth.alipay.com/oauth2/appToAppAuth.htm?app_id=2021004167603274&redirect_uri=" . urlencode(self::Notify) . "&state=STORE_ID_VALUE";
        return $url;

    }


}